$(function () {
    $("#topbar ul li[class=siderbar-tab]").on('click', function(e) {
        var cls = e.target.id;
        if(e.target.nodeName == "I") {
            cls = e.target.parentElement.id;
        }
        for(var i = 0; i < $('.main-sidebar .sidebar ul').length; i++)
        {
            var obj = $('.main-sidebar .sidebar ul')[i];
            if(cls == obj.id) {
                $('.main-sidebar .sidebar ul[id=' + obj.id + ']').css("display", "block");
            } else {
                $('.main-sidebar .sidebar ul[id=' + obj.id + ']').css("display", 'none');
            }
        }
    });

    $('.mailbox-messages input[type="checkbox"]').iCheck({
        checkboxClass: 'icheckbox_flat-blue',
        radioClass: 'iradio_flat-blue'
    });

    //Enable check and uncheck all functionality
    $(".checkbox-toggle").click(function () {
      var clicks = $(this).data('clicks');
      if (clicks) {
        //Uncheck all checkboxes
        $(".mailbox-messages input[type='checkbox']").iCheck("uncheck");
        $(".fa", this).removeClass("fa-check-square-o").addClass('fa-square-o');
      } else {
        //Check all checkboxes
        $(".mailbox-messages input[type='checkbox']").iCheck("check");
        $(".fa", this).removeClass("fa-square-o").addClass('fa-check-square-o');
      }
      $(this).data("clicks", !clicks);
    });

    //Handle starring for glyphicon and font awesome
    $(".mailbox-star").click(function (e) {
      e.preventDefault();
      //detect type
      var $this = $(this).find("a > i");
      var glyph = $this.hasClass("glyphicon");
      var fa = $this.hasClass("fa");

      //Switch states
      if (glyph) {
        $this.toggleClass("glyphicon-star");
        $this.toggleClass("glyphicon-star-empty");
      }

      if (fa) {
        $this.toggleClass("fa-star");
        $this.toggleClass("fa-star-o");
      }
    });
    //END FULL SCREEN


});
